#include "HelloWorldScene.h"
#include"LSYEasyWorld.h"
#include"LSYEasyBody.h"
#include"Tool.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
    
	auto layer = HelloWorld::create();
	
    scene->addChild(layer);

    return scene;
}

bool HelloWorld::init()
{
	if (!Node::init())
    {
        return false;
    }
	createWorld();
	createCircle();
	createRect();

	this->scheduleUpdate();
    return true;
}

void HelloWorld::createWorld()
{
	pWorld = LSYEasyWorld::createWorld(b2Vec2{ 0, 0 });
	LSYEasyWorld::createDebug();
}

void HelloWorld::createCircle()
{
	LSYEasyBody::createCircle(b2Vec2{ 100.0,100.0 }, 60);
}

void HelloWorld::createRect()
{
	LSYEasyBody::createBox(b2Vec2(200, 100), b2Vec2(50, 30));
}

void HelloWorld::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
{
	Node::draw(renderer, transform, flags);
	ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);
	kmGLPushMatrix();
	pWorld->DrawDebugData();
	kmGLPopMatrix();
	CHECK_GL_ERROR_DEBUG();
}

void HelloWorld::update(float dt)
{
	LSYEasyWorld::updateWorld();
}

void HelloWorld::onExit()
{
	REALSE_NULL(pWorld);
}
